package com.wang.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo1 {
    public static void main(String[] args) {
        Collection collection = new ArrayList();
        collection.add("a");
        collection.add("b");
        collection.add("c");
        System.out.println(collection.size());
        if (collection.contains("a")){
            System.out.println("存在a,删除!");
            boolean a = collection.remove("a");
            if (a) System.out.println("删除成功");
        }
        //利用for迭代
        for(Object o:collection)System.out.println(o);
        //利用iterator迭代器进行迭代
        Iterator iterator = collection.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
            System.out.println("读取出一个删掉一个");
            iterator.remove();
        }
        System.out.println(collection.isEmpty());



    }
}
